package cn.shujuhai.cms.domain;

import cn.shujuhai.common.domain.BaseDomain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.validation.annotation.Validated;

import java.time.LocalDateTime;

/**
 * 邮件记录表，用于存储邮件的基本信息、状态及内容
 *
 * @TableName email_record
 */
@EqualsAndHashCode(callSuper = true)
@TableName(value = "email_record")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Validated
public class EmailRecord extends BaseDomain {
    /**
     * 邮件ID
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 邮件主题
     */
    @Size(min = 1, max = 100, message = "邮件主题不能超过100个字符")
    private String subject;

    /**
     * 邮件发送状态: 0=草稿, 1=待发送, 2=成功, 3=失败
     */
    private Integer status;

    /**
     * 邮件发送时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sendTime;

    /**
     * 邮件附件路径
     */
    private String emailAttachment;

    /**
     * 邮件收件人分组ID
     */
    private Long groupId;

    /**
     * 邮件内容
     */
    private byte[] content;

    /**
     * 栏目ID
     */
    @NotNull
    private Long channelId;

    /**
     * 文章ID
     */
    @NotNull
    private Long articleId;
    /**
     * 重新发送次数
     */
    private Integer retry;
    /**
     * 邮件已发送数量
     */
    private Integer count;
    /**
     * 发送成功数量
     */
    @TableField(exist = false)
    private Integer successNum;

    /**
     * 发送失败数量
     */
    @TableField(exist = false)
    private Integer failNum;
    /**
     * 收件人总数
     */
    @TableField(exist = false)
    private Integer recipientNum;

}